package util;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class PreventRefresh {
	public static final String TOKENNAME="refresh";
	
	@SuppressWarnings("unchecked")
	public static void saveTime(HttpServletRequest request,String msg){
		HttpSession session=request.getSession();
		List list=(List)request.getAttribute(TOKENNAME);
		if(null==list){
			list=new ArrayList();
		}
		list.add(msg);
		session.setAttribute(TOKENNAME, list);
	}
	public static String getTime(HttpServletRequest request){
		String msg=System.currentTimeMillis()+"";
		saveTime(request,msg);
		return msg;
	}
	@SuppressWarnings("unchecked")
	public static boolean chek(HttpServletRequest request){
		boolean flag=false;
		List list=(List)request.getSession().getAttribute(TOKENNAME);
		String msg=request.getParameter(TOKENNAME);
		if(list.contains(msg)){
			list.remove(msg);
			flag=true;
		}
		return flag;
	}

}
